package br.com.main.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

public class DialogBoxRecuperarSenha extends DialogBox {
	
	private VerticalPanel painelMain;
	private HorizontalPanel painel;
	private Button enviar;
	private TextBox email;
	private Image carregar;
	private Label inf;
public DialogBoxRecuperarSenha() {
		super(true);
		setText("Recuperar Senha e Login");

		enviar = new Button("Enviar");
		carregar = new Image("imagens/carrega2.gif");
		carregar.setVisible(false);
		
		painelMain = new VerticalPanel();
		painel = new HorizontalPanel();
		email = new TextBox();
		
		painelMain.add(inf = new Label("Digite o seu email"));
		painel.add(email);
		painel.add(enviar);
		painelMain.add(painel);
		painelMain.add(carregar);
		
		setWidget(painelMain);
		setAnimationEnabled(true);
		setGlassEnabled(true);
		center();
		
		enviar.addClickHandler(new ClickHandler() {
			
			@Override
			public void onClick(ClickEvent arg0) {
				
				carregar.setVisible(true);
				
				inf.setVisible(false);
				painel.setVisible(false);
				
				getServico().recuperarSenha(email.getValue().trim(), new AsyncCallback<String>() {
					
					@Override
					public void onSuccess(String arg0) {
						
						painelMain.add(new Label(arg0));
						carregar.setVisible(false);
						
					}
					
					@Override
					public void onFailure(Throwable arg0) {
						
					}
				});
			}
		});
		
	}
	
	private ComunServicoAsync getServico() {
		return GWT.create(ComunServico.class);
	}


}
